package mm.view;

import java.util.HashMap;
import java.util.Map;

import mm.util.Constants;
import mm.util.I18NMap;

public class Page {

	private String url;
	private String content;
	private Map<String, Object> beans;
	private boolean noFrame;

	public Page() {
		beans=new HashMap<String, Object>();
	}

	public Page(String url) {
		this();
		setURL(url);
	}

	public Page(Map<String, Object> beans) {
		this();
		setBeans(beans);
	}

	public Page(String url, Map<String, Object> beans) {
		this();
		setURL(url);
		setBeans(beans);
	}

	public String getURL() {
		return url;
	}

	public void setURL(String url) {
		this.url = url;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public void setBeans(Map<String, Object> beans) {
		if(beans != null)
			this.beans = beans;
	}

	public Map<String, Object> getBeans() {
		return beans;
	}

	public void putBean(String beanName, Object bean) {
		this.beans.put(beanName, bean);
	}

	public Object getBean(String beanName) {
		return beans.get(beanName);
	}

	public boolean isNoFrame() {
		return noFrame;
	}

	public void setNoFrame(boolean noFrame) {
		this.noFrame = noFrame;
	}

	public void setError(User user, Exception e) {
		this.putBean("error", I18NMap.getInstance(user!=null?user.getLocale():Constants.DEFAULT_LOCALE).get(e.getMessage()));
	}

}
